import {Component} from 'react';
import React from 'react';
import {connect} from 'umi';

import HighPerformTable from '@/components/HighPerformTable';
import {Divider} from 'antd';
import APIS from '@/apis';
import FilterByCourse from "@/components/FilterByCourse";

class ExamCheckManager extends Component<any, any> {
  actionRef: any;

  requestGetData(
    params: {
      pageSize?: number;
      current?: number;
    },
    sorter: {
      [key: string]: 'ascend' | 'descend';
    },
    filter: {
      [key: string]: React.ReactText[];
    },
  ) {
    return APIS.ExamAPI.GetFinishedTestList({...params, sorter, filter, course: this.state.course});
  }

  constructor(props: any) {
    super(props);
    this.state = {
      course: -1,
      allCourse: []
    }
  }

  componentDidMount() {
    APIS.CourseAPI.GetCourseList({
      current: 1,
      pageSize: 99999,
      state: -1
    }).then(res => this.setState({allCourse: res.data})).catch(e => {
      console.error(e)
    })
  }

  clomns: any = [
    {
      title: '考试名称',
      dataIndex: 'examName',
    },
    {
      title: '考试描述',
      dataIndex: 'description',
      width: "35%",
      ellipsis: true
    },
    {
      title: '使用试卷',
      dataIndex: 'paperName'
    },
  ];

  handleDataImport() {
  }

  handleDataExport() {
  }

  render() {
    const {allCourse} = this.state;
    return (
      <div>
        {/* <KeywordFilterSearch
          filters={[
            {
              title: '学院',
              multiple: false,
              keywords: ['全部', '计算机学院', '轨道交通学院', '电气工程学院'],
            },
            { title: '年级', multiple: false, keywords: ['全部', '2015', '2016', '2017', '2018'] },
          ]}
        ></KeywordFilterSearch> */}
        <FilterByCourse
          course={allCourse}
          getValue={(value) => {
            this.setState({course: value});
            this.actionRef?.reload();
          }}/>
        <Divider></Divider>
        <HighPerformTable<any>
          ref={(ref) => (this.actionRef = ref)}
          requestGetData={this.requestGetData.bind(this)}
          additionOptions={[
            {
              title: '查看',
              onClick: (record: any) => {
                //console.log(record);
                this.props.history.push({
                  pathname: '/teaching/check/students',
                  state: {examId: record.id, paperId: record.paperId, description: record.description}
                });
              },
            },
          ]}
          // toolBarRender={() => [
          //   <Button key={0} type="primary" onClick={() => this.actionRef.handleModalVisible(true)}>
          //     <PlusOutlined /> 新增班级
          //   </Button>,
          //   <Button key={1} type="primary" onClick={() => this.handleDataImport()}>
          //     批量导入
          //   </Button>,
          //   <Button key={2} type="primary" onClick={() => this.handleDataExport()}>
          //     批量导出
          //   </Button>,
          // ]}
          columns={this.clomns}
        />
      </div>
    );
  }
}

export default connect()(ExamCheckManager);
